<template>
  <div class="aboutUs" id="aboutUs">
    <div class="aboutUs-banner">
      <img
        src="../../assets/images/aboutus_banner.png"
        id="aboutUs-banner"
        alt=""
      />
    </div>
    <div class="aboutUs-content">
      <div class="about-navbar-wrap" id="navbar-wrap">
        <a
          href="#jieshao"
          :class="activeIndex === 'jieshao' ? 'a-active' : ''"
          @click="checkContent('jieshao')"
          >企业介绍</a
        >
        <a
          href="#zhaoxian"
          :class="activeIndex === 'zhaoxian' ? 'a-active' : ''"
          @click="checkContent('zhaoxian')"
          >招贤纳士</a
        >
        <a
          href="#guanyu"
          :class="activeIndex === 'guanyu' ? 'a-active' : ''"
          @click="checkContent('guanyu')"
          >联系我们</a
        >
      </div>

      <div class="about-content-right" id="content-wrap">
        <page-company id="jieshao"></page-company>

        <page-pap></page-pap>

        <page-us></page-us>
      </div>
    </div>
  </div>
</template>

<script>
import pageCompany from "./components/pageCompany.vue";
import pagePap from "./components/pagePap.vue";
import pageUs from "./components/pageUs.vue";

export default {
  components: { pageCompany, pagePap, pageUs },
  data() {
    return {
      activeIndex: "jieshao",
    };
  },
  watch: {
    $route: {
      handler: function(val, oldVal) {
        this.activeIndex = val.hash;
        this.activeIndex = this.activeIndex.replace("#", "");
        console.log(this.activeIndex);
        this.$nextTick(() => {
          // this.setSliderTop(this.activeIndex);
        });
      },
      // 深度观察监听
      deep: true,
    },
  },
  methods: {
    setSliderTop(activeIndex) {
      if (activeIndex !== "guanyu") {
        var div = document.getElementById(activeIndex);
        let offsetTop = div.offsetTop;
        document.getElementById("navbar-wrap").style.top =
          offsetTop + 30 + "px";
        // offsetTop + 30 + "px";
      }
    },
    checkContent(activeIndex) {
      this.activeIndex = activeIndex;
      // this.setSliderTop(this.activeIndex);
    },
  },
  mounted() {
    console.log(this.$route.hash);
    this.activeIndex = this.$route.hash;
    this.activeIndex = this.activeIndex.replace("#", "");
    console.log(this.activeIndex);
    this.$nextTick(() => {
      // this.setSliderTop(this.activeIndex);
    });
  },
};
</script>

<style lang="scss" scoped>
.aboutUs {
  width: 100%;
  .aboutUs-banner {
    position: fixed;
    left: 0;
    top: 60px;
    width: 100%;
    height: 220px;
    z-index: 999;
    img {
      height: 220px;
      object-fit: cover;
      width: 100%;
    }
  }
  position: relative;
}
.aboutUs-content {
  background: green;
  position: relative;
}
.about-navbar-wrap {
  width: 271px;
  position: fixed;
  left: 3%;
  top: 300px;
  a {
    box-sizing: border-box;
    padding-left: 22px;
    display: block;
    height: 57px;
    line-height: 57px;
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #666666;
  }
  .a-active {
    border-left: 3px solid #2590f4;
    background: #e7f0f8;
    color: #2590f4;
  }
}

.about-content-right {
  overflow: hidden;
  position: absolute;
  width: 909px;
  left: 24%;
  top: 300px;
  border: green;
}
</style>
